import { ReactElement } from 'react'
import { Form, Select, Col } from 'antd'
import { ConditionSchema } from '@components/schema/condition'
import { ComponentProps } from './interface'
const { Item } = Form
const { Option } = Select

function Main ({ dictionary, secretaries = [] }: ComponentProps): ReactElement {
  return (
    <Col span={8}>
      <Item label='办案秘书' name='processer'>
        <Select placeholder='请选择' showSearch allowClear>
          <Option value='无'>无</Option>
          <Option value='全部'>全部</Option>
          {secretaries.map((li, i) => <Option key={i} value={li.realname}>{li.realname}</Option>)}
        </Select>
      </Item>
    </Col>
  )
}

export function initFormat (f: { [k: string]: any }, t: { [k: string]: any }): void {
  if (typeof f.processer === 'string') {
    t.processer = f.processer
  }
}

export function changeFormat (o: { [k: string]: any }): void {

}

export function getCondition (d: { [k: string]: any }): ConditionSchema[] {
  const condition: ConditionSchema[] = []
  if (typeof d.processer === 'string' && d.processer !== '全部') {
    if (d.procedure === '无') {
      condition.push({ k: 'processer', o: 'null' })
    } else {
      condition.push({ k: 'processer', o: 'like', v: `%${d.processer}%` })
    }
  }
  return condition
}

export default {
  component: Main,
  initFormat,
  changeFormat,
  getCondition
}
